package com.study.config;


import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhuzi
 * 2024/3/25 11:39
 */
@Slf4j
@Configuration
public class AppRedissonAutoConfigurationCustomizer implements RedissonAutoConfigurationCustomizer {


    /**
     * 配置完毕之后可以通过此设置
     *
     * @param cfg Config配置
     */
    @SneakyThrows
    @Override
    public void customize(Config cfg) {
        System.out.println(StringUtils.center("自定义配置", 30, "-"));
        System.out.println(cfg.toYAML());
        //System.out.println("编码" + cfg.getCodec());
        //cfg.setCodec(new org.redisson.codec.FstCodec());
        //cfg.setCodec(new org.redisson.codec.SerializationCodec());
        cfg.setCodec(new FastJsonCodec());

        cfg.setTransportMode(TransportMode.NIO);
        SingleServerConfig singleServerConfig = cfg.useSingleServer();
        singleServerConfig.setKeepAlive(true);
        singleServerConfig.setPingConnectionInterval(30000);
    }

}
